﻿// ## 2023/11/06 # 铃 # 创建逻辑 用于进攻时候AI的设施修建##


namespace 核心任务优化
{
    //=======================================================================================


    bool 调试模式 = false;
    bool 调试模式2 = false;

    pk::list<pk::unit @> list_candidate_unit;
    pk::list<pk::building @> list_candidate_building;
    pk::list<pk::unit @> list_ally_unit;
    pk::unit @src_unit;

    array<float> heishu_weight(6, 0.0f);
    array<unit_order_info> unit_order_info_arr;
    float heishu_null = 0.0f;
    float heishu_weak = 0.5f;
    float heishu_normal = 1.0f;
    float heishu_strong = 1.5f;

//---------------------------------------------------------------------------

    void optimize_order(pk::ai_context@ ai_context, pk::unit @unit)
    {
        unit_order_info_arr.resize(0);
        int unit_id = unit.get_id();

        pk::force@ force = @ai_context.force;
        int src_force_id = force.get_id();
       // if(force.get_id() == 27) return;


        int service = pk::get_service(unit);

        uint8 unit_deploy_type = 0;
        uint8 deploy_target = 255;
        int deploy_target_force_id;

        auto scenario_ai_table_unit = pk::get_scenario().ai_table.unit[unit_id];
        if (int(scenario_ai_table_unit.force) == src_force_id)
        {
            unit_deploy_type = scenario_ai_table_unit.deploy_type;// 种类(3:运输，4:建设)
            deploy_target = scenario_ai_table_unit.deploy_target;
            deploy_target_force_id = pk::get_building(deploy_target).get_force_id();

        }
        pk::building@ deploy_target_building = pk::get_building(deploy_target);
        pk::person@ leader = pk::get_person(unit.leader);
        int unit_pos_base_id = pk::get_building_id(unit.get_pos());

        // *****************************************************************************************************************
        // ************************************************野战的任务优化 部队撤退***************************************
        // *******************************************************************************************************************
           //前置撤退条件
           //单个撤退的任务优化
        if (unit.troops < 1500 or unit.energy < 20 or int(unit.food * 10 / unit.troops) <= 10)
        {
            if (pk::is_alive(unit) and unit.type == 部队类型_战斗 and unit.order != 部队任务_撤退)
                if (single_withdraw(unit)) return;
        }

           //回防逻辑
        if (pk::is_alive(unit) and unit.type == 部队类型_战斗 and unit.order != 部队任务_撤退)
            if (back_retreat(unit)) return;




// *****************************************************************************************************************
// ************************************************野战的任务优化 修改建筑逻辑***************************************
// *******************************************************************************************************************
        if (pk::is_alive(unit) and unit.type == 部队类型_战斗 and unit.order != 部队任务_撤退)
        {
            if (unit.weapon <= 兵器_战马 or unit.weapon > 兵器_投石)
            {
                unit_order_info_arr.insertLast(进攻型建筑设施修建优化::func_build(unit));
                unit_order_info_arr.insertLast(进攻型建筑设施修建优化::func_repair(unit));
            }



    // *****************************************************************************************************************
    // ************************************************野战的任务优化 野战部队选择***************************************
    // *******************************************************************************************************************
        //野战优化 对 部队
            if (unit.weapon != 兵器_冲车 and unit.weapon != 兵器_木兽)
                unit_order_info_arr.insertAt(0, func_change_target_unit(unit));


    // *****************************************************************************************************************
    // ************************************************野战的任务优化 野战部队选择***************************************
    // *******************************************************************************************************************
        //野战优化 对 建筑
            unit_order_info_arr.insertAt(0, func_change_target_building(unit));

            if (调试模式)
                pk::trace(pk::format("func266,部队:{}", pk::decode(pk::get_name(unit))));


                     //对各种行为做一些修正:
                     //正常情况下,修楼应该是分数高于盖楼的,不然会出现一直盖而不修的情况,这里用HP来做约束.
            for (int i = 0;i < int(unit_order_info_arr.length);i++)
            {
                if (unit_order_info_arr[i].order == 部队任务_设置 and unit.weapon != 兵器_冲车 and unit.weapon != 兵器_木兽 and unit.weapon != 兵器_投石 and unit.weapon != 兵器_井阑)
                {
                    //盖楼默认为1000分.(相当于1000伤害的价值)
                    unit_order_info_arr[i].score = 1000;

                     //对于攻击力很低的部队,修楼更有意义
                    if (unit.attr.stat[部队能力_攻击] < 30) unit_order_info_arr[i].score += 500;
                    else if (unit.attr.stat[部队能力_攻击] < 60) unit_order_info_arr[i].score += 200;

                    //每多500块钱,多100分 钱多的部队优先级高
                    unit_order_info_arr[i].score += (unit.gold * 100 / 500);

                    //任务对象坐标周围敌军和友军越多,分越高
                    unit_order_info_arr[i].score += (ally_enemy_count(unit, unit_order_info_arr[i].pos, 3).second - 1) * 200;
                    unit_order_info_arr[i].score += (ally_enemy_count(unit, unit_order_info_arr[i].pos, 3).first - 1) * 100;
                }

                if (unit_order_info_arr[i].order == 部队任务_修复 and unit.weapon != 兵器_冲车 and unit.weapon != 兵器_木兽 and unit.weapon != 兵器_投石 and unit.weapon != 兵器_井阑)
                {
                     //修楼默认为800分.(相当于800伤害的价值)
                    unit_order_info_arr[i].score = 800;

                    auto tar_building = pk::get_building(unit_order_info_arr[i].pos);

                    //对于攻击力很低的部队,修楼更有意义
                    if (unit.attr.stat[部队能力_攻击] < 30) unit_order_info_arr[i].score += 300;
                    else if (unit.attr.stat[部队能力_攻击] < 60) unit_order_info_arr[i].score += 200;

                       //适性差的更适合盖楼
                    if (unit.attr.tekisei[pk::equipment_id_to_heishu(unit.weapon)] == 适性_B)unit_order_info_arr[i].score += 100;
                    if (unit.attr.tekisei[pk::equipment_id_to_heishu(unit.weapon)] == 适性_C)unit_order_info_arr[i].score += 200;


                     //未完成的建筑很高权重,相当于500伤害(但是附近要有人,没人的话完全不着急修 ,一般这种情况都发生在结束的战场,或者后方)
                    if (ally_enemy_count(unit, tar_building.pos, 5).second > 0)
                    {
                        if (tar_building !is null and !tar_building.completed)
                            unit_order_info_arr[i].score += 500;
                    }

                     //每亏500HP,就加100分.
                    else  if (tar_building !is null and pk::get_max_hp(tar_building) - tar_building.hp > 500)
                    {
                        unit_order_info_arr[i].score += (pk::get_max_hp(tar_building) - tar_building.hp) / 5;
                    }

                    //3格附近敌军越多,越应该修.每个150分.如果没有敌军,则扣150分(相当于150伤害)
                    if (tar_building.facility <= 设施_连弩楼)
                    {
                        unit_order_info_arr[i].score += (ally_enemy_count(unit, tar_building.pos, 3).second - 1) * 150;
                    }

                    //距离太远不适合去修,3格以外 每一格减分150
                    if (pk::get_distance(tar_building.pos, unit.pos) >= 3)
                        unit_order_info_arr[i].score = unit_order_info_arr[i].score - (pk::get_distance(tar_building.pos, unit.pos) - 3) * 150;


                // pk::trace(pk::format("func266,{},距离{},分数{}", pk::decode(pk::get_name(unit)),  pk::get_distance(tar_building.pos, unit.pos),unit_order_info_arr[i].score));

                       //适性差的更适合盖楼
                    if (unit.attr.tekisei[pk::equipment_id_to_heishu(unit.weapon)] == 适性_B)unit_order_info_arr[i].score += 200;
                    if (unit.attr.tekisei[pk::equipment_id_to_heishu(unit.weapon)] == 适性_C)unit_order_info_arr[i].score += 500;
                }

                if (unit_order_info_arr[i].order == 部队任务_攻击)
                {
                    auto dst_unit = pk::get_unit(unit_order_info_arr[i].pos);
                    if (dst_unit !is null)
                    {
                         // *************************************************** 基准伤害计算********************************************
                        int 预估部队伤害 = 0;
                        int 预估反击伤害 = 0;

                         // 基本伤害计算
                        pk::int_int attacker_add_stat = UNIT_ATTR::get_unit_additional_atk_def(unit);
                        pk::int_int target_add_stat = UNIT_ATTR::get_unit_additional_atk_def(dst_unit);
                        int atk = unit.attr.stat[部队能力_攻击] + attacker_add_stat.first;
                        int def = dst_unit.attr.stat[部队能力_防御] + target_add_stat.second;

                        int dst_neibor_enemy_count = ally_enemy_count(src_unit, dst_unit.pos, 1).second;

                        pk::equipment @equipment = pk::get_equipment(unit.weapon);
                        int max = 0;

                        for (int j = 0; j < 可用战法_末; j++)
                        {
                            if (equipment.tactics[j])
                            {
                                pk::tactics@ tactics = pk::get_tactics(j);
                                int tekisei = tactics.tekisei;
                                if (tekisei <= pk::get_tekisei(unit, unit.weapon))// 适性是否达标
                                {
                                    int energy_cost = tactics.energy_cost;
                                    if (unit.get_energy() >= energy_cost)// 气力够不够
                                    {
                                        int troops_atk = tactics.troops_atk;

                                        if (j == 战法_乱射 or j == 战法_旋风 or j == 战法_横扫 or (j == 战法_攻城投石 and pk::has_tech(unit, 技巧_霹雳)))
                                        {
                                            if (dst_neibor_enemy_count >= 1)
                                                troops_atk = troops_atk * dst_neibor_enemy_count;

                                        }
                                        if (troops_atk > max) max = troops_atk;
                                    }
                                }
                            }
                        }

                        预估部队伤害 = get_attack_damage(unit, dst_unit, max);

                        预估反击伤害 = int(get_attack_damage(dst_unit, unit, 10) * 0.8);

                        //远程不受到伤害
                        if (unit.weapon == 兵器_弩 or unit.weapon == 兵器_井阑 or unit.weapon == 兵器_投石)  预估反击伤害 = 0;

                        //戟兵反击伤害减半
                        if (unit.weapon == 兵器_戟)  预估反击伤害 /= 2;

                        if (dst_unit.weapon == 兵器_弩)预估反击伤害 /= 2;

                        if (dst_unit.weapon >= 兵器_冲车)预估反击伤害 = 0;

                        //己方兵力越大,越倾向于和对方拼伤害,打出的伤害权重更高
                        if (unit.troops > dst_unit.troops * 2)
                            unit_order_info_arr[i].score += int(预估部队伤害 * 1.5 - 预估反击伤害 * 0.6);

                         //己方兵力越小,越倾向于找软柿子捏,保留自己的实力
                        else if (unit.troops < dst_unit.troops / 2)
                            unit_order_info_arr[i].score += int(预估部队伤害 * 0.8 - 预估反击伤害 * 1.2);

                        else
                            unit_order_info_arr[i].score += int(预估部队伤害 * 1.2 - 预估反击伤害 * 0.8);

                            // **********************************************杂项修正********************************************

                             // 君主.都督都加分(因为击杀后会导致其他人降低士气)
                        if (dst_unit.leader == pk::get_kunshu_id(dst_unit))
                            unit_order_info_arr[i].score += int(预估部队伤害 * 0.3);
                        else if (dst_unit.leader == pk::get_totoku_id(dst_unit))
                            unit_order_info_arr[i].score += int(预估部队伤害 * 0.2);

                        // 优先攻击少血部队,最多可以增加 35%
                        if (int(dst_unit.troops) <= 3500)
                            unit_order_info_arr[i].score += 预估部队伤害 * (3500 - dst_unit.troops) / 10000;

                        // 优优先攻击残血部队,最多可以再增加 30%
                        if (int(dst_unit.troops) <= 1500)
                            unit_order_info_arr[i].score += 预估部队伤害 * (1500 - dst_unit.troops) / 5000;

                         // 优先攻击兵器部队,最多可以再增加 10%
                        if (dst_unit.weapon == 兵器_木兽 or dst_unit.weapon == 兵器_冲车 or dst_unit.weapon == 兵器_井阑)
                            unit_order_info_arr[i].score += int(预估部队伤害 * 0.1);

                         // 优先攻击投石,最多可以再增加 15%
                        if (dst_unit.weapon == 兵器_投石)
                            unit_order_info_arr[i].score += int(预估部队伤害 * 0.15);

                        // 每多一个空格就增加2%(容易被包围的部队)
                        unit_order_info_arr[i].score += int(预估部队伤害 * get_empty_pos(dst_unit.pos, 1, 1).length * 2 / 100);

                        // 每远1格,减少3%
                        unit_order_info_arr[i].score -= int(预估部队伤害 * pk::get_distance(unit.pos, dst_unit.pos) * 3 / 100);

                        //对于src_unit来说,unit周围有多少src的友军,每多一个多3%,目的是靠近友军大军
                        unit_order_info_arr[i].score += int(预估部队伤害 * ally_enemy_count(src_unit, unit.pos, 3).first * 3 / 100);

                        //贴身的友军(未来用于包围),每多一个多5%
                        unit_order_info_arr[i].score += int(预估部队伤害 * ally_enemy_count(src_unit, unit.pos, 1).first * 5 / 100);

                            //对于src_unit来说,unit周围有多少src的友军建筑,每多1个多200分
                        unit_order_info_arr[i].score += ally_enemy_count_building(src_unit, unit.pos, 3).first * 200;

                        if (unit_deploy_type == 部队出征类型_攻击 and dst_unit.get_force_id() != deploy_target_force_id)
                            unit_order_info_arr[i].score -= 300;


                        if (调试模式)
                            pk::trace(pk::format("对部队攻击:序号:{},任务{},目标{},对象{},预估部队伤害{},预估反击伤害{},分数{}", i, get_order_info(unit_order_info_arr[i].order), pk::decode(pk::get_name(dst_unit)), unit_order_info_arr[i].target, 预估部队伤害, 预估反击伤害, unit_order_info_arr[i].score));
                    }

                    auto dst_building = pk::get_building(unit_order_info_arr[i].pos);
                    if (dst_building !is null)
                    {
                        //耐久伤害计算
                        int def = batt::get_building_def(dst_building);
                        int tactics_atk = 10;
                        if (unit.weapon == 兵器_木兽 or unit.weapon == 兵器_冲车)tactics_atk = 60;
                        if (unit.weapon == 兵器_投石) tactics_atk = 30;
                        if (unit.weapon == 兵器_战马) tactics_atk = 5;
                        if (unit.stock[兵器_冲车].amount + unit.stock[兵器_木兽].amount >= 1) tactics_atk = 60;
                        int 预估耐久伤害 = int(batt::core_unit_hp_damage(unit.troops, unit.attr.stat[部队能力_攻击], tactics_atk, def));

                        //守军伤害计算
                        int 预估守军伤害 = 0;
                        int base_atk = 0, base_def = 0, base_troops = 0;
                        UNIT_ATTR::get_base_unit_attr(dst_building, base_atk, base_def, base_troops);
                        int troops_atk = 10;
                        if (unit.weapon == 兵器_井阑 or unit.weapon == 兵器_投石) troops_atk = 30;
                        if (unit.weapon == 兵器_战马) troops_atk = 5;

                          //分情况讨论

                           //对府兵的情况
                        if (ch::is_valid_spec_id(ch::to_spec_id(dst_building.get_id())))
                        {
                            auto spec_t = ch::get_spec_p(ch::to_spec_id(dst_building.get_id()));
                            预估守军伤害 = int(batt::core_unit_troops_damage(unit.troops, unit.attr.stat[部队能力_攻击], troops_atk, base_def));

                            unit_order_info_arr[i].score += 预估耐久伤害 * 6 + pk::min(预估守军伤害, spec_t.troops);
                        }

                        //对据点的情况
                        else if (dst_building.facility < 设施_阵)
                        {
                            预估守军伤害 = int(batt::core_unit_troops_damage(unit.troops, unit.attr.stat[部队能力_攻击], troops_atk, base_def));
                            unit_order_info_arr[i].score += 预估耐久伤害 * 10 + 预估守军伤害 * 3 / 2;
                        }

                        //对普通军事设施
                        else
                        {
                            //对于不能反击的建筑 优先级会高一些
                            if (dst_building.facility == 设施_箭楼 or dst_building.facility == 设施_连弩楼 or dst_building.facility == 设施_投石台) unit_order_info_arr[i].score += 预估耐久伤害 * 8;
                            else if (dst_building.facility == 设施_阵 or dst_building.facility == 设施_砦 or dst_building.facility == 设施_城塞)unit_order_info_arr[i].score += 预估耐久伤害 * 5;
                            else if (dst_building.facility == 设施_太鼓台 or dst_building.facility == 设施_军乐台) unit_order_info_arr[i].score += 预估耐久伤害 * 6;
                            else unit_order_info_arr[i].score += 预估耐久伤害 * 3; //内政设施
                        }

                         // 优先攻击少血建筑,极差为200.
                        if (int(dst_building.hp) <= 1000)
                            unit_order_info_arr[i].score += int((1000.0 - float(dst_building.hp)) / 5);

                        // 优先攻击残血建筑,极差为200.
                        if (int(dst_building.hp) <= pk::get_max_hp(dst_building) / 5)
                            unit_order_info_arr[i].score += int((1.0 - dst_building.hp * 1.0 / pk::get_max_hp(dst_building)) * 200);

                        // 每远1格,扣30分.10格就扣300分了.
                        unit_order_info_arr[i].score += 50 - pk::get_distance(unit.pos, dst_building.pos) * 30;

                        //对于src_unit来说,unit周围有多少src的友军,每多一个自己的友军多30分.
                        if (dst_building.facility == 设施_箭楼 or dst_building.facility == 设施_连弩楼 or dst_building.facility == 设施_投石台)
                            unit_order_info_arr[i].score += ally_enemy_count(src_unit, dst_building.pos, 3).first * 30;


                        if (unit_deploy_type == 部队出征类型_攻击 and dst_building.get_force_id() != deploy_target_force_id)
                            unit_order_info_arr[i].score -= 1000;

                    }
                }

                if (调试模式)
                {
                    if (pk::is_valid_pos(unit_order_info_arr[i].pos) and pk::get_hex(unit_order_info_arr[i].pos).has_building)
                        pk::trace(pk::format("序号:{},任务{},目标{},对象{},分数{}", i, get_order_info(unit_order_info_arr[i].order), pk::decode(pk::get_name(pk::get_building(unit_order_info_arr[i].pos))), unit_order_info_arr[i].target, unit_order_info_arr[i].score));

                    if (pk::is_valid_pos(unit_order_info_arr[i].pos) and pk::get_hex(unit_order_info_arr[i].pos).has_unit)
                        pk::trace(pk::format("序号:{},任务{},目标{},对象{},分数{}", i, get_order_info(unit_order_info_arr[i].order), pk::decode(pk::get_name(pk::get_unit(unit_order_info_arr[i].pos))), unit_order_info_arr[i].target, unit_order_info_arr[i].score));

                }

            }

            if (unit_order_info_arr.length > 0)
            {
                unit_order_info_arr.sort(function(a, b) {
                    return a.score > b.score;
                });

                if (调试模式)
                    pk::trace(pk::format("最终任务{},目标{},{},对象{},分数{}", get_order_info(unit_order_info_arr[0].order), unit_order_info_arr[0].pos.x, unit_order_info_arr[0].pos.y, unit_order_info_arr[0].target, unit_order_info_arr[0].score));

                if (unit.get_id() == unit_order_info_arr[0].id and unit_order_info_arr[0].order >= 0 and pk::is_valid_pos(unit_order_info_arr[0].pos))
                    pk::set_order(unit, unit_order_info_arr[0].order, unit_order_info_arr[0].pos, unit_order_info_arr[0].target);

            }
        }


    // *****************************************************************************************************************
    // ************************************************攻城的任务优化 征服到攻城***************************************
    // *******************************************************************************************************************
    //如果城市已经接近崩溃, 而且把部队的任务修改为直接攻击城市,不攻击周遭建筑,不执行攻击府的指令
        if ((unit.order == 部队任务_征服 and unit.target_type == 部队任务对象_据点))
        {
            if (pk::is_alive(unit) and unit.type == 部队类型_战斗 and unit.order != 部队任务_撤退)
                change_conquer_to_siege(unit);
        }

    // *****************************************************************************************************************
    // ************************************************攻城的任务优化 攻城到征服***************************************
    // *******************************************************************************************************************
        // //如果进攻部队战斗力不足,把部队的任务修改为直接征服,也可以继续执行攻击府的判定指令
        //  //当攻击部队的小于防御能力的2倍时,优先征服战(消耗战),而非攻城战
        // if (((unit.order == 部队任务_攻击 or unit.order == 部队任务_攻城) and unit.target_type == 部队任务对象_据点 and pk::is_valid_base_id(unit.target)))
        // {
        //     if (pk::is_alive(unit) and unit.type == 部队类型_战斗 and unit.order != 部队任务_撤退)
        //         change_siege_to_conquer(unit);
        // }

    // *****************************************************************************************************************
    // ************************************************野战的任务优化 异常建设部队***************************************
    // *******************************************************************************************************************
        //C级部队一般都是建设部队,如果不在自己所在的城市,就可以撤退了.
        auto member_list = get_member_list(unit);
        int best_tekisei = get_tekisei(member_list, pk::equipment_id_to_heishu(unit.weapon));

        if (调试模式2) pk::trace(pk::format("func266,{}前置前置判断,best_tekisei{},unit.weapon{}", pk::decode(pk::get_name(unit)), best_tekisei, unit.weapon));

        if ((best_tekisei == 0 or unit.weapon == 兵器_剑) and unit.type == 部队类型_战斗 and unit.weapon != 兵器_走舸 and unit.weapon != 兵器_楼船 and unit.weapon != 兵器_斗舰)
        {
            if (调试模式2) pk::trace(pk::format("func266,{}前置判断,部队长期任务{},短期任务{}", pk::decode(pk::get_name(unit)), unit_deploy_type, unit.order));
            if (pk::get_distance(unit.pos, pk::get_building(service).pos) > 10 or pk::get_building_id(unit.pos) != service or (unit_deploy_type != 部队出征类型_建设 and unit.order != 部队任务_设置))
            {
                pk::building @dst = find_withdraw_base(unit);
                pk::set_order(unit, 部队任务_撤退, dst.pos);
                if (调试模式2) pk::trace(pk::format("func266,{}适性太低回城,部队长期任务{},短期任务{}", pk::decode(pk::get_name(unit)), unit_deploy_type, unit.order));

            }

        }

    }
    int get_weapon_type(int weapon_id)
    {
        int weapon_type = -1;
        if (weapon_id == 兵器_剑)
            weapon_type = 0;
        else if (weapon_id >= 兵器_枪 and weapon_id <= 兵器_战马)
            weapon_type = 1;
        else if (weapon_id == 兵器_冲车 or weapon_id == 兵器_木兽)
            weapon_type = 2;
        else if (weapon_id >= 兵器_井阑 or weapon_id == 兵器_投石)
            weapon_type = 3;
        else if (weapon_id == 兵器_走舸)
            weapon_type = 4;
        else if (weapon_id > 兵器_走舸)
            weapon_type = 5;

        return weapon_type;
    }

    // *************************************************** 回防********************************************
        // 防御部队：回防
    bool back_retreat(pk::unit @unit)
    {
        if (!pk::is_alive(unit))
            return false;
        if (unit.type != 部队类型_战斗)
            return false; // 如果不是战斗部队，则排除

        if (unit.order == 部队任务_撤退)
            return false;

        //距离太近的不考虑
        if (pk::get_distance(unit.pos, pk::get_building(pk::get_service(unit)).pos) < 5)
            return false;

        pk::person@ leader = pk::get_person(unit.leader);
        pk::building@ base = pk::get_building(pk::get_service(unit));
        pk::list<pk::unit @> dst_unit_list;
        dst_unit_list.clear();


        if (ai::base_around_enemy_troops[leader.service] > 20000 and ai::base_around_enemy_troops[leader.service] > ai::base_around_self_troops[leader.service])
        {
            pk::array<pk::point> arr_t = pk::range(base.pos, 1, 3);
            for (int j = 0; j < int(arr_t.length); j++)
            {
                pk::point pos = arr_t[j];
                pk::hex @hex = pk::get_hex(pos);

                pk::unit @target_unit = pk::get_unit(arr_t[j]);
                if (!hex.has_building and target_unit !is null and pk::is_alive(target_unit) and pk::is_enemy(unit, target_unit))
                {

                    dst_unit_list.add(target_unit); // 如果敌方部队可攻击，则添加到列表中

                }
            }
            if (dst_unit_list.count > 0)
            {
                dst_unit_list.sort(function(a, b) {
                    int a_score = a.attr.stat[部队能力_攻击];
                    int b_score = a.attr.stat[部队能力_攻击];;

                    if (a.weapon > 兵器_战马)  a_score += 50;
                    if (b.weapon > 兵器_战马)  b_score += 50;


                    return a_score > b_score;
                });

                pk::set_order(unit, 部队任务_攻击, dst_unit_list[0].pos);

                if (调试模式2) pk::info(pk::format("{} 向:{}回防", pk::decode(pk::get_name(pk::get_person(unit.leader))), pk::decode(pk::get_name(pk::get_building(leader.service)))));
                return true;

            }

        }
        return false;
    }

   // *************************************************** 攻城的任务优化 攻城到征服********************************************
    void change_siege_to_conquer(pk::unit @unit)
    {
        int force_id = unit.get_force_id();
        int attacking_troops = ai::force_attack_base_troops[force_id][unit.target];
        int defending_troops = ai::base_around_self_troops[unit.target] + ch::city_spec_troops(pk::get_building(unit.target)) / 3 + pk::get_troops(pk::get_building(unit.target)) * pk::get_building(unit.target).energy / 120;

        //当攻击部队的小于防御能力的2倍时,优先征服战(消耗战),而非攻城战
        if (unit.order == 部队任务_攻击 and attacking_troops < defending_troops * 2 and defending_troops > 30000 and int(pk::get_building(unit.target).hp) > int(pk::get_max_hp(pk::get_building(unit.target)) * 0.8))
        {
            string src_unit_name = pk::decode(pk::get_name(unit));
            if (调试模式2) pk::trace(pk::format("func266:{}部队任务从攻击修改为征服,目标城市{},野战兵力,城市兵力{},HP{}", src_unit_name, pk::decode(pk::get_name(pk::get_building(unit.target))), pk::get_troops(pk::get_building(unit.target)), ai::base_around_self_troops[unit.target], pk::get_building(unit.target).hp));
            pk::set_order(unit, 部队任务_征服, pk::get_building(unit.target).pos);
        }
    }

       // *************************************************** 攻城的任务优化 征服到攻城********************************************
    void change_conquer_to_siege(pk::unit @unit)
    {
        int force_id = unit.get_force_id();
        if (pk::is_valid_base_id(unit.target) and pk::get_building_id(unit.pos) == unit.target and pk::get_distance(unit.pos, pk::get_building(unit.target).pos) < 10)
        {
            if (unit.order == 部队任务_征服 and ((pk::get_troops(pk::get_building(unit.target)) < 5000 or pk::get_building(unit.target).hp < 3000) or (ai::base_around_self_troops[unit.target] == 0 and pk::get_troops(pk::get_building(unit.target)) < 8000)))
            {
                string src_unit_name = pk::decode(pk::get_name(unit));
                if (调试模式2) pk::trace(pk::format("func266:{}部队任务从征服修改为攻击,目标城市{},兵力{},HP{}", src_unit_name, pk::decode(pk::get_name(pk::get_building(unit.target))), pk::get_troops(pk::get_building(unit.target)), pk::get_building(unit.target).hp));
                pk::set_order(unit, 部队任务_攻击, pk::get_building(unit.target).pos);
                return;
            }
        }
    }

            // 修改攻击目标部队的函数
    array<unit_order_info>  func_change_target_building(pk::unit @unit)
    {
        @src_unit = @unit;
        array<unit_order_info> unit_order_arr;
        unit_order_info info;
        unit_order_arr.resize(0);
        //pk::trace(pk::format("攻击者{}:", pk::decode(pk::get_name(unit))));

        pk::list<pk::building @> list_building = get_able_building_list(unit);

        int target_count = list_building.count;
        if (target_count == 0)
            return unit_order_arr;
        array<array<int>>  score(建筑_末, array<int>(2, int(-1)));
        for (int x = 0; x < int(list_building.count); x++)
        {
            pk::building@ dst_building = list_building[x];

            if (dst_building.facility == 设施_土垒) continue;

        // pk::trace(pk::format("攻击者{}:遍历到{},x0:{},x1:{}", pk::decode(pk::get_name(unit)), pk::decode(pk::get_name(dst_unit)), score[x][0], score[x][1]));

            info.id = unit.get_id();
            info.order = 部队任务_攻击;
            info.pos = list_building[x].pos;
            info.score = 1;
            info.target = -1;

            unit_order_arr.insertLast(info);
        }

            //        // 显示部队目标变更对话框
            // if (pk::is_in_screen(unit.pos))
            //     say_change_target_unit(unit, dst_unit);

        return unit_order_arr;
    }


            // 修改攻击目标部队的函数
    array<unit_order_info> func_change_target_unit(pk::unit @unit)
    {
        @src_unit = @unit;
        array<unit_order_info> unit_order_arr;
        unit_order_info info;
        unit_order_arr.resize(0);

       // pk::trace(pk::format("攻击者{}:", pk::decode(pk::get_name(unit))));

        pk::list<pk::unit @> list_unit = get_able_unit_list(unit);

        int target_count = list_unit.count; // 候选目标部队数量
        if (target_count == 0)
            return  unit_order_arr;
        array<array<int>>  score(部队_末, array<int>(2, int(-1)));
        for (int x = 0; x < int(list_unit.count); x++)
        {
            pk::unit@ dst_unit = list_unit[x];
            //pk::trace(pk::format("攻击者{}:遍历到{},", pk::decode(pk::get_name(unit)), pk::decode(pk::get_name(dst_unit))));

           // pk::trace(pk::format("攻击者{}:遍历到{}加入列表", pk::decode(pk::get_name(unit)), pk::decode(pk::get_name(dst_unit))));


            info.id = unit.get_id();
            info.order = 部队任务_攻击;
            info.pos = list_unit[x].pos;
            info.score = 1;
            info.target = -1;

            unit_order_arr.insertLast(info);
        }

            //        // 显示部队目标变更对话框
            // if (pk::is_in_screen(unit.pos))
            //     say_change_target_unit(unit, dst_unit);

        return unit_order_arr;
    }

    void say_change_target_unit(pk::unit @src_unit, pk::unit @dst_unit)
    {
        string str_f0 = pk::decode(pk::get_name(pk::get_force(src_unit.get_force_id())));
        string str_p0 = pk::decode(pk::get_name(pk::get_person(src_unit.leader)));
        string str_w0 = get_weapon_name(src_unit.weapon);
        string str_t0 = get_tekisei_name(pk::get_tekisei(src_unit));
        string str_f2 = pk::decode(pk::get_name(pk::get_force(dst_unit.get_force_id())));
        string str_p2 = pk::decode(pk::get_name(pk::get_person(dst_unit.leader)));
        string str_w2 = get_weapon_name(dst_unit.weapon);
        string str_t2 = get_tekisei_name(pk::get_tekisei(dst_unit));
        string str_color = get_heishu_color(dst_unit.weapon);

        string str_line0 = pk::format("\x1b[2x{}军\x1b[1x{}队\x1b[17x({}{})\x1b[0x任务变更!!", str_f0, str_p0, str_w0, str_t0);
        string str_line1 = pk::format("开始向\x1b[2x{}军\x1b[1x{}队{}{}{}\x1b[0x发起攻击", str_f2, str_p2, str_color, str_w2, str_t2);

        pk::person @leader = pk::get_person(src_unit.leader);
        pk::say(pk::encode(pk::format("{}\n{}", str_line0, str_line1)), leader);
    }


    // ********************************************************** 单个撤退的任务优化*************************************************
    bool single_withdraw(pk::unit @unit)
    {
    // 兵力小于1000,撤退距离在大约6回合以内撤退,太远就放弃.
        int force_id = unit.get_force_id();
        pk::person @leader = pk::get_person(unit.leader);
        pk::building @dst = find_withdraw_base(unit);
        if (dst is null) return false;
        string target_name = pk::decode(pk::get_name(dst));
        int move_days = pk::max(unit_distance[dst.get_id()][pk::get_building_id(unit.pos)], 5); //撤退需要几天
        int food_days = int(unit.food * 10 / unit.troops);      //粮草还够几天

        if (unit.troops < 1200 or unit.troops * unit.energy / 100 < 500)
        {
            if (调试模式2)  pk::trace(pk::format("func266:{}部队撤退,兵力{}", pk::decode(pk::get_name(unit)), unit.troops));
            if (pk::is_in_screen(unit.pos))
                pk::say(pk::encode(pk::format("无力再战,向\x1b[2x{}\x1b[0x撤退吧!", target_name)), leader);
            pk::set_order(unit, 部队任务_撤退, dst.pos);
            return true;
        }

        else if (unit.energy < 15)
        {
            if (调试模式2)  pk::trace(pk::format("func266:{}部队撤退,士气{}", pk::decode(pk::get_name(unit)), unit.energy));
            if (pk::is_in_screen(unit.pos))
                pk::say(pk::encode(pk::format("士兵们士气低落已无法再战,向\x1b[2x{}\x1b[0x撤退吧!", target_name)), leader);
            pk::set_order(unit, 部队任务_撤退, dst.pos);

            return true;
        }

        else if (food_days <= move_days and food_days <= 10) //如果撤退需要6天,那么第五天就要考虑回家
        {

            if (调试模式2)  pk::trace(pk::format("func266:{}部队撤退,food_days{}, move_days{} ", pk::decode(pk::get_name(unit)), food_days, move_days));
            if (pk::is_in_screen(unit.pos))
                pk::say(pk::encode(pk::format("粮草已尽,已无法再战,向\x1b[2x{}\x1b[0x撤退吧!", target_name)), leader);
            pk::set_order(unit, 部队任务_撤退, dst.pos);
            return true;
        }
        return false;
    }

            // ********************************************************** 搜索可攻击敌方建筑的函数*************************************************
    void get_list_candidate_building(pk::unit @unit)
    {
        // 初始化列表
        if (!pk::is_alive(unit))
            return;
        list_candidate_building.clear();
        int weapon_id = unit.weapon;
        int weapon_type = get_weapon_type(weapon_id); // 0:剑, 1:战斗, 2:冲车, 3:井阑, 4:水军 5:大船

        pk::array<pk::point> arr_t = pk::range(unit.pos, 1, 5);
        for (int j = 0; j < int(arr_t.length); j++)
        {
            pk::hex @hex = pk::get_hex(arr_t[j]);
            if (hex.has_building)
            {
                pk::building @target_building = pk::get_building(arr_t[j]);
                if (target_building !is null and pk::is_alive(target_building) and (pk::is_enemy(unit, target_building) or (target_building.facility < 设施_阵 and target_building.get_force_id() == -1)))
                {
                    list_candidate_building.add(target_building); // 如果敌方建筑可攻击，则添加到列表中
                }
            }
        }
    }

    // ********************************************************** 搜索可攻击敌方部队的函数*************************************************

    void get_list_candidate_unit(pk::unit @unit)
    {
        // 初始化列表
        if (!pk::is_alive(unit))
            return;
        list_candidate_unit.clear();
        int weapon_id = unit.weapon;
        int weapon_type = get_weapon_type(weapon_id); // 0:剑, 1:战斗, 2:冲车, 3:攻城其他, 4:水军

        // 冲车不作为搜索目标
        if (weapon_id == 兵器_冲车)
            return;

        pk::array<pk::point> arr_t = pk::range(unit.pos, 1, 6);
        for (int j = 0; j < int(arr_t.length); j++)
        {
            pk::point pos = arr_t[j];
            pk::hex @hex = pk::get_hex(pos);

            pk::unit @target_unit = pk::get_unit(arr_t[j]);
            if (!hex.has_building and target_unit !is null and pk::is_alive(target_unit) and pk::is_enemy(unit, target_unit))
            {
                list_candidate_unit.add(target_unit); // 如果敌方部队可攻击，则添加到列表中

            }
        }
    }

    // ********************************************************** 搜索附近我方部队 用于给异常部队复制任务*************************************************
    void get_list_ally_unit(pk::unit @unit)
    {
        // 初始化列表
        if (!pk::is_alive(unit))
            return;
        list_ally_unit.clear();
        int weapon_id = unit.weapon;
        int weapon_type = get_weapon_type(weapon_id); // 0:剑, 1:战斗, 2:冲车, 3:攻城其他, 4:水军


        pk::array<pk::point> arr_t = pk::range(unit.pos, 1, 6);
        for (int i = 0; i < int(arr_t.length); i++)
        {
            pk::point pos = arr_t[i];
            pk::hex @hex = pk::get_hex(pos);

            pk::unit @target_unit = pk::get_unit(arr_t[i]);
            if (!hex.has_building and target_unit !is null and pk::is_alive(target_unit) and unit.get_force_id() == target_unit.get_force_id() and unit.type == 部队类型_战斗)
            {
                if (unit.order == 部队任务_撤退) continue;
                if (unit.order == 部队任务_拦截 or unit.order == 部队任务_攻击 or unit.order == 部队任务_征服 or unit.order == 部队任务_攻城 or unit.order == 部队任务_移动)
                    list_ally_unit.add(target_unit); // 如果我方部队战斗中，则添加到列表中

            }
        }
    }

    pk::int_int ally_enemy_count(pk::unit @src_unit, pk::point pos, int distance)
    {
        int enemy_troops = 0;
        int self_troops = 0;
        pk::array<pk::point> arr_t = pk::range(pos, 1, distance);
        for (int i = 0; i < int(arr_t.length); i++)
        {
            pk::point pos0 = arr_t[i];
            pk::hex @hex = pk::get_hex(pos0);

            pk::unit @target_unit = pk::get_unit(arr_t[i]);
            if (hex.has_unit and !pk::is_enemy(src_unit, target_unit))self_troops++;
            if (hex.has_unit and pk::is_enemy(src_unit, target_unit))enemy_troops++;
        }

        return pk::int_int(self_troops, enemy_troops);
    }

    pk::int_int ally_enemy_count_building(pk::unit @src_unit, pk::point pos, int distance)
    {
        int enemy_building = 0;
        int self_building = 0;
        pk::array<pk::point> arr_t = pk::range(pos, 1, distance);
        for (int i = 0; i < int(arr_t.length); i++)
        {
            pk::point pos0 = arr_t[i];
            pk::hex @hex = pk::get_hex(pos0);
            if (!hex.has_building) continue;
            pk::building @target_building = pk::get_building(arr_t[i]);
            if (target_building !is null and !pk::is_enemy(src_unit, target_building))self_building++;
            if (target_building !is null and pk::is_enemy(src_unit, target_building))enemy_building++;
        }

        return pk::int_int(self_building, enemy_building);
    }


    pk::list<pk::unit @> get_able_unit_list(pk::unit @unit)
    {
        pk::list<pk::unit @> unit_list;
        unit_list.clear();
        pk::array<pk::point> move_arr_range = pk::get_movable_pos(unit);

        for (int arr_index = 0; arr_index < int(move_arr_range.length); arr_index++)
        {
            int max_range = get_atk_range(unit).second;

            pk::array<pk::point> range = pk::range(move_arr_range[arr_index], 1, max_range);
            for (int i = 0; i < int(range.length); i++)
            {
                if (!pk::is_valid_pos(range[i]))
                    continue;

                pk::unit @unit0 = pk::get_unit(range[i]);

                if (unit0 is null)
                    continue;
                if (unit_list.contains(unit0))
                    continue;

                if (pk::is_enemy(unit0, unit))
                {
                    unit_list.add(unit0);
                }
            }
        }
        return unit_list;
    }


    pk::list<pk::building @> get_able_building_list(pk::unit @unit)
    {
        pk::list<pk::building @> building_list;
        pk::array<pk::point> move_arr_range = pk::get_movable_pos(unit);

        uint8 unit_deploy_type = 0;
        uint8 deploy_target = 255;
        auto scenario_ai_table_unit = pk::get_scenario().ai_table.unit[unit.get_id()];
        unit_deploy_type = scenario_ai_table_unit.deploy_type;// 种类(3:运输，4:建设)
        deploy_target = scenario_ai_table_unit.deploy_target;

        for (int arr_index = 0; arr_index < int(move_arr_range.length); arr_index++)
        {
            int max_range = get_atk_range(unit).second;
            pk::array<pk::point> range = pk::range(move_arr_range[arr_index], 1, max_range);
            for (int i = 0; i < int(range.length); i++)
            {
                if (!pk::is_valid_pos(range[i]))
                    continue;

                pk::building @building0 = pk::get_building(range[i]);

                if (building0 is null)
                    continue;

                //不是自己目标城市的建筑,尽量不去攻击
                if (unit_deploy_type == 部队出征类型_攻击 and int(pk::get_building_id(building0.pos)) != int(deploy_target))
                    continue;

                if (building_list.contains(building0))
                    continue;

                if (pk::is_enemy(building0, unit))
                {
                    building_list.add(building0);
                }
            }
        }
        return building_list;
    }


    pk::list<pk::person @> get_member_list(pk::unit@ unit)
    {
        pk::list<pk::person @> list;
        for (int i = 0; i < 3; ++i)
        {
            if (pk::is_valid_person_id(unit.member[i]))
            {
                pk::person @person0 = pk::get_person(unit.member[i]);
                if (pk::is_alive(person0))
                    list.add(person0);
            }
        }
        return list;
    }

    int get_tekisei(pk::list<pk::person @> list, int heishu_id)
    {
        int best_tekisei = 0;
        for (int i = 0; i < list.count; ++i)
        {
            if (list[i] !is null)
            {
                if (list[i].tekisei[heishu_id] > best_tekisei)
                    best_tekisei = list[i].tekisei[heishu_id];
            }
            //pk::trace("兵种"+heishu_id+"最佳适性"+best_tekisei);
        }
        return best_tekisei;
    }



    // **********************************************************寻找撤退据点**********************************************************
    int loc_id;
    int service_id;
    pk::building @find_withdraw_base(pk::unit @unit)
    {
        array<pk::building @> dst_base_arr;

        loc_id = pk::get_building_id(unit.pos);
        if (loc_id < 0 or loc_id >= 据点_末)
            return null;
        service_id = pk::get_service(unit);

        for (int i = 0; i < 据点_末; i++)
        {
            pk::building @dst_base = pk::get_building(i);

            if (!pk::is_alive(dst_base))
                continue;

            //太远不行
            if (unit_distance[loc_id][i] > 8)
                continue;

                //判断势力
            if (dst_base.get_force_id() != unit.get_force_id())
                continue;

            if (unit.is_player())
            {
                pk::district @district = pk::get_district(pk::get_building(i).get_district_id());
                if (district.no == 1)continue;
            }

            dst_base_arr.insertLast(dst_base);
        }
        if (dst_base_arr.length == 0)return null;
        dst_base_arr.sort(function(a, b) {
            return unit_distance[loc_id][a.get_id()] - ((a.get_id() == service_id) ? 2 : 0) < unit_distance[loc_id][b.get_id()] - ((b.get_id() == service_id) ? 2 : 0);
        });

        if (dst_base_arr.length <= 0)
            return pk::get_building(pk::get_service(unit));
        else return  dst_base_arr[0];
    }

    // 获取部队的攻击最小和最大射程
    pk::int_int get_atk_range(pk::unit @unit)
    {
        pk::int_int atk_range = pk::int_int(1, 1);
        if (!pk::is_alive(unit) or unit.weapon == 兵器_剑)
            return atk_range;
        int weapon_id = unit.weapon;
        if (weapon_id < 0)
            pk::trace(pk::format("{},兵装{},", pk::decode(pk::get_name(unit), weapon_id)));

        pk::equipment @epq = pk::get_equipment(unit.weapon);
        string eqp_name = pk::decode(pk::get_name(epq));
        string info = pk::format("{}", eqp_name);
        int min_range = 5;
        int max_range = 1;
        for (int j = 0; j < 可用战法_末; j++)
        {
            if (epq.tactics[j])
            {
                pk::tactics @tts = pk::get_tactics(j);
                string tts_name = pk::decode(pk::get_name(tts));
                info += pk::format(" {}({},{})", tts_name, tts.min_range, tts.max_range);
                min_range = pk::min(min_range, tts.min_range);
                max_range = pk::max(max_range, tts.max_range);
            }
        }
        if (weapon_id == 兵器_弩 and unit.has_tech(技巧_强弩))
            max_range += 1;
        if (weapon_id == 兵器_战马 and (unit.has_tech(技巧_骑射) or unit.has_skill(特技_白马)))
            max_range = pk::max(2, max_range);
        if ((weapon_id == 兵器_井阑 or weapon_id == 兵器_投石) and unit.has_skill(特技_射程))
            max_range += 1;
        atk_range = pk::int_int(min_range, max_range);
        return atk_range;
    }

    int get_attack_damage(pk::unit @unit, pk::unit @dst_unit, int max)
    {
                                 // 基本伤害计算
        pk::int_int attacker_add_stat = UNIT_ATTR::get_unit_additional_atk_def(unit);
        pk::int_int target_add_stat = UNIT_ATTR::get_unit_additional_atk_def(dst_unit);
        int atk = unit.attr.stat[部队能力_攻击] + attacker_add_stat.first;
        int def = dst_unit.attr.stat[部队能力_防御] + target_add_stat.second;

        int dst_neibor_enemy_count = ally_enemy_count(src_unit, dst_unit.pos, 1).second;


                    // 考虑相克关系
        int atk_index = batt::weapon_to_index(unit.weapon);
        int tar_index = batt::weapon_to_index(dst_unit.weapon);
        //异常情况
        if (atk_index == -1 || tar_index == -1)
            return 0;
        float res = batt::兵种克制关系[atk_index][tar_index];
        //res = (res - 1.0) * 2 + 1;

        return int(batt::core_unit_troops_damage(unit.troops, atk, max, def) * res);
    }

    string get_weapon_name(int weapon_id)
    {
        string weapon_name;
        switch (weapon_id)
        {
            case 兵器_剑:
                weapon_name = "剑兵";
                break;
            case 兵器_枪:
                weapon_name = "枪兵";
                break;
            case 兵器_戟:
                weapon_name = "戟兵";
                break;
            case 兵器_弩:
                weapon_name = "弓兵";
                break;
            case 兵器_战马:
                weapon_name = "骑兵";
                break;
            case 兵器_冲车:
                weapon_name = "冲车";
                break;
            case 兵器_井阑:
                weapon_name = "井栏";
                break;
            case 兵器_投石:
                weapon_name = "投石";
                break;
            case 兵器_木兽:
                weapon_name = "木兽";
                break;
            case 兵器_走舸:
                weapon_name = "走舸";
                break;
            case 兵器_楼船:
                weapon_name = "楼船";
                break;
            case 兵器_斗舰:
                weapon_name = "斗舰";
                break;
            default:
                weapon_name = "??";
                break;
        }
        return weapon_name;
    }

    string get_tekisei_name(int tekisei)
    {
        string tekisei_name;
        switch (tekisei)
        {
            case 适性_C:
                tekisei_name = "C";
                break;
            case 适性_B:
                tekisei_name = "B";
                break;
            case 适性_A:
                tekisei_name = "A";
                break;
            case 适性_S:
                tekisei_name = "S";
                break;
            default:
                tekisei_name = "↑";
                break;
        }
        return tekisei_name;
    }
    // 获取兵种颜色函数
    string get_heishu_color(int weapon_id)
    {
        string text_color;
        float weight = heishu_weight[pk::equipment_id_to_heishu(weapon_id)];
        if (weapon_id == 兵器_剑)
            text_color = "\x1b[2x"; // 绿色
        else if (weight == heishu_null)
            text_color = "\x1b[29x"; // 红色
        else if (weight == heishu_weak)
            text_color = "\x1b[16x"; // 橙色
        else if (weight == heishu_normal)
            text_color = "\x1b[17x"; // 黄色
        else if (weight == heishu_strong)
            text_color = "\x1b[2x"; // 绿色
        else
            text_color = "\x1b[0x"; // 白色
        return text_color;
    }

    array<pk::point> get_empty_pos(pk::point pos, int distance_min, int distance_max)
    {
        array<pk::point> empty_pos;
        array<pk::point> range_pos_arr = pk::range(pos, distance_min, distance_max);

        for (int arr_index = 0; arr_index < int(range_pos_arr.length); arr_index++)
        {
            pk::point range_pos = range_pos_arr[arr_index];
            if (!pk::is_valid_pos(range_pos))
                continue;

            pk::hex @hex = pk::get_hex(range_pos);
            if (hex.has_building)
                continue;
            if (hex.has_unit)
                continue;

            int terrain_id = hex.terrain;
            if (!pk::is_valid_terrain_id(terrain_id))
                continue;
            if (!pk::is_enabled_terrain(terrain_id))
                continue;

            empty_pos.insertLast(range_pos_arr[arr_index]);
        }

        return empty_pos;
    }
    string get_order_info(int order)
    {
        string name;
        switch (order)
        {
            case 0:
                name = "待命";
                break;
            case 1:
                name = "移动";
                break;
            case 2:
                name = "设置";
                break;
            case 3:
                name = "攻击";
                break;
            case 4:
                name = "撤退";
                break;
            case 5:
                name = "拦截";
                break;
            case 6:
                name = "护卫";
                break;
            case 7:
                name = "攻城";
                break;
            case 8:
                name = "修复";
                break;
            case 9:
                name = "征服";
                break;
            case 10:
                name = "补给";
                break;
            case 11:
                name = "歼灭";
                break;
            case 12:
                name = "追随";
                break;
            case 13:
                name = "末";
                break;
            default:
                name = "无";
                break;
        }

        return name;
    }

}
